/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.oea.hibernate.entities;

import com.oea.hibernate.utilities.HibernateUtil;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author unnati
 */
@Table(name = "tests")
@Entity
public class Test extends AbstractEntity
{
    @GeneratedValue
    
    @Column(name="id")
    @Id
    protected  Long id;
    
    @Column(name="name")
    protected  String name;

    @Column(name = "duration")
    protected  String duration;
    
    @Column(name="tdate")
    protected  String tdate;
    
   @Column(name = "cutoffmarks")
   protected  int cutoffmarks;
   
  

    public int getCutoffmarks() {
        return cutoffmarks;
    }

    public void setCutoffmarks(int cutoffmarks) {
        this.cutoffmarks = cutoffmarks;
    }
    
    @Column(name="totalquestions")
    protected  int totalquestions;
    
    @Column(name = "positivemarking")
    protected  float  positivemarking;
    
    @Column(name="negativemarking")
    protected float  negativemarking;
    
    @Column(name = "ttime")
    protected  String ttime;
    
    @Column(name = "description")
    protected  String description;
    
    @Column(name = "eid")
    protected  Long eid;
//    
    @Column(name = "subid")
    protected Long subid;
    
    @Column(name = "addedby")
    protected  Long addedby;
    
    @Transient
    protected Exam exam;
    
    @Transient
    protected Subject subject;
    
    @Transient
    protected  Faculty faculty;

    public Exam getExam() {
        return exam;
    }

    public void setExam( ) {
        this.exam = (Exam) new Exam().getById(eid);
    }

    public Subject getSubject() {
        return subject;
    }

    public void setSubject() {
        this.subject = (Subject) new Subject().getById(subid);
    }

    public Faculty getFaculty() {
        return faculty;
    }

    public void setFaculty( ) {
        this.faculty = (Faculty) new Faculty().getById(addedby);
    }
    
    

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }

    public String getTdate() {
        return tdate;
    }

    public void setTdate(String tdate) {
        this.tdate = tdate;
    }

  

    public int getTotalquestions() {
        return totalquestions;
    }

    public void setTotalquestions(int totalquestions) {
        this.totalquestions = totalquestions;
    }

    public float getPositivemarking() {
        return positivemarking;
    }

    public void setPositivemarking(float positivemarking) {
        this.positivemarking = positivemarking;
    }

    public float getNegativemarking() {
        return negativemarking;
    }

    public void setNegativemarking(float negativemarking) {
        this.negativemarking = negativemarking;
    }

    public String getTtime() {
        return ttime;
    }

    public void setTtime(String ttime) {
        this.ttime = ttime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getEid() {
     return eid;
    }

    public void setEid(Long eid) {
        this.eid = eid;
    }

    public Long getSubid() {
        return subid;
    }

    public void setSubid(Long subid) {
        this.subid = subid;
    }

    public Long getAddedby() {
        return addedby;
    }

    public void setAddedby(Long addedby) {
        this.addedby = addedby;
    }
  
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public Test getSubjectName()
    {
        Test t=null;
        
        Session s=HibernateUtil.getSessionFactory().openSession();
        Query q=s.createQuery("from Test where id="+this.id+"");
        t=(Test) q.list().get(0);
        
        return t;
    }
    
    public static List<Test> GetAllByEid(Long eid)
    {
        List<Test> li_test_by_eid=null;
        
        try 
        {
            Session s=HibernateUtil.getSessionFactory().openSession();
            Query q=s.createQuery("from Test where eid="+eid+"");
            li_test_by_eid=q.list();
           
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        return li_test_by_eid;
    }
    public static List<Test> GetAllTestByEidAndTid(Long tid,Long eid)
    {
        List<Test> li_tets_by_tid_eid=null;
        
        try 
        {
            Session s=HibernateUtil.getSessionFactory().openSession();
            Query q=s.createQuery("from Test where id="+tid+" and eid="+eid+"");
            li_tets_by_tid_eid=q.list();
           // System.out.println("ro"+li_tets_by_tid_eid.size());
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        return li_tets_by_tid_eid;
    }
}
